<template>
  <div class="container">
    <data-view
      propViewKey="material_crud"
      propViewForm="base/material/detail.vue"
      :propIsTdesign="true"
      :propInitData="{isHospitalMaterial: false}"
      @extra-button-click="extraButtonClick"
      ref="dv"
      :propNoEditRow="true"
    />

    <!--导入商品-->
    <customDrawer title="导入商品" ref="customDrawerImportDataCustom"
                  :widthPx="600" :heightPx="500"
                  hideConfirm
    >
      <template #content>
        <dataImportArea
          @success="dataImportSuccess"
          ref="dataImportAreaImportDataCustom"
          :config="importConfig"
        />
      </template>
    </customDrawer>
  </div>
</template>

<script>
import dataImportArea from '@/views/base/help/dataImportArea.vue'
export default {
  help: '商品管理-列表',
  data() {
    return {
      importConfig: {
        name: 'box-4',
        title: '4、商品',
        sheetName: '供应商系统商品',
        help: `
          1、【下载模板】维护好数据 -> 【选择文件】导入数据<br>
          2、<span class='span-msg-nopad'>供应商不存在的忽略</span><br>
          3、<span class='span-msg-nopad'>厂商会自动创建</span><br>
          4、<span class='span-msg-nopad'>【只新增商品】</span><br>
          5、<span class='span-msg-nopad'>去重规则：供应商、商品名称、商品规格、生产厂家，如果找到匹配的则忽略</span><br>
          `,
        downloadPath: '/base/materials/excelDownloadTempForDataImport',
        importPath: '/base/materials/excelImportForDataImport'
      }
    }
  },
  components: {
    dataImportArea
  },
  methods: {
    menuActiveCall() {
      this.$refs.dv.ocRefresh()
    },
    extraButtonClick(para) {
      let {key: buttonKey} = para.button
      if (buttonKey == 'disabledBatch') {
        if (para.data.length == 0) {
          this.utilMessage.error('请先勾选列表需要操作的商品')
          return false
        }
        this.utilMessage.confirmInput('请输入禁用原因<span class="span-tip">禁用后该商品不可供货，也不需要维护资质</span>', (inputValue) => {
          this.utilVue.loadShow(true)
          let idList = para.data.map(o => o.id)
          this.$ajax.post('base/materials/disabledBatch', {idList: idList, remark: inputValue }).then(response => {
            this.utilVue.loadHide()
            if (response.code == 0) {
              this.utilMessage.success(response.msg)
              this.menuActiveCall()
            }
          })
        })
      }
      if (buttonKey == 'enabledBatch') {
        if (para.data.length == 0) {
          this.utilMessage.error('请先勾选列表需要操作的商品')
          return false
        }
        this.utilMessage.confirm('是否启用所选商品', (inputValue) => {
          this.utilVue.loadShow(true)
          let idList = para.data.map(o => o.id)
          this.$ajax.post('base/materials/enabledBatch', {idList: idList }).then(response => {
            this.utilVue.loadHide()
            if (response.code == 0) {
              this.utilMessage.success(response.msg)
              this.menuActiveCall()
            }
          })
        })
      }else  if (buttonKey == 'importDataCustom') { //导入商品
        this.$refs.dataImportAreaImportDataCustom.clear()
        this.$refs.customDrawerImportDataCustom.show()
      }
    },

    // 商品导入成功后
    dataImportSuccess(data, resp) {
      this.menuActiveCall()
      // let wrapper = this.$newWrapper()
      // this.$refs.dataView.setQueryForm('remark',data.tms)
      // this.utilMessage.info('已为您查询本次导入的数据')
    }
  }
}
</script>
